package com.huobao.yunying.activitys_store;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import org.xutils.common.util.LogUtil;
import org.xutils.view.annotation.ViewInject;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.yunying.entity.StoreDetail;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpConst;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.yunying.utils.ImageUtils;
import com.huobao.zhangying.R;

import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class Act_Store_Detail extends HuobaoBaseActivity {

	@ViewInject(R.id.tv_store_username)
	private TextView tv_store_username;
	@ViewInject(R.id.tv_store_address)
	private TextView tv_store_address;
	@ViewInject(R.id.tv_store_tel)
	private TextView tv_store_tel;
	@ViewInject(R.id.tv_store_number)
	private TextView tv_store_number;
	@ViewInject(R.id.tv_store_chanpin)
	private TextView tv_store_chanpin;
	@ViewInject(R.id.tv_store_dengji)
	private TextView tv_store_dengji;
	@ViewInject(R.id.tv_store_createtime)
	private TextView tv_store_createtime;
	@ViewInject(R.id.tv_storename)
	private TextView tv_storename;
	@ViewInject(R.id.imgView)
	private ImageView imgView;
	private String id;
	private String phone = null;

	protected void showDetail(StoreDetail detail) {
		phone = detail.tel;
		tv_store_username.setText(detail.user_name);
		tv_store_address.setText(detail.address);
		tv_store_tel.setText(detail.tel);
		tv_store_number.setText(detail.goods_count);
		tv_store_chanpin.setText(detail.industry);
		tv_store_dengji.setText(detail.sgrade);
		tv_store_createtime.setText(detail.add_time);
		tv_storename.setText(detail.store_name);
		ImageUtils.loadimg(imgView,detail.credit_image);
	}

	@Override
	protected int getContentView() {
		return R.layout.layout_store_detail;
	}

	@Override
	protected String getTitleText() {
		return "店铺详情";
	}

	@Override
	protected void init() {
		id = getIntent().getStringExtra("id");
		getStoreDetail();
	}

	private void getStoreDetail() {
		Map<String, String> map = HttpUtil.getParams(HttpConst.FRIST_KEY, "store", HttpConst.SECOND_KEY, "details",
				"id", id);
		Http.getInstant().sendRequest(context, map, new HttpListener() {

			@Override
			public void onHttpSuccess(String result) {
				JSONObject jsonObject = JSON.parseObject(result);
				StoreDetail detail = JSON.parseObject(jsonObject.getString("retval"), StoreDetail.class);
				showDetail(detail);
			}

			@Override
			public void onHttpError(String error) {
			}
		});
	}

	public void onTelClick(View view) {
		if (phone == null)
			return;
		Uri uri = Uri.parse("tel:" + phone);
		Intent intent = new Intent(Intent.ACTION_DIAL, uri);
		startActivity(intent);
	}
}
